package com.tianhao.luo.queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @author tianhao.luo@hand-china.com
 */
public class BlockingQueueDemo {
    public static void main(String[] args) {
        // 1.创建阻塞队列
        BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);
        //
        //// 第一组
        //// 添加数据
        //System.out.println(blockingQueue.add("a"));
        //System.out.println(blockingQueue.add("b"));
        //System.out.println(blockingQueue.add("c"));
        ////队列已满，无法继续存放
        ////System.out.println(blockingQueue.add("d"));
        //
        //System.out.println(blockingQueue.remove());
        //System.out.println(blockingQueue.remove());
        //System.out.println(blockingQueue.remove());
        ////队列已空，无法继续取出
        ////System.out.println(blockingQueue.remove());
        //
        //
        //// 第二组
        //// 添加数据
        //System.out.println(blockingQueue.offer("a"));
        //System.out.println(blockingQueue.offer("b"));
        //System.out.println(blockingQueue.offer("c"));
        ////队列已满，无法继续存放返回false
        //System.out.println(blockingQueue.offer("d"));
        //
        //System.out.println(blockingQueue.poll());
        //System.out.println(blockingQueue.poll());
        //System.out.println(blockingQueue.poll());
        ////队列已空，poll出得元素为null
        //System.out.println(blockingQueue.poll());

    }
}
